package appconfig

import (
	"fmt"
	"github.com/spf13/viper"
)

type appConfig struct {
	Mysql
	Redis
	Es
	QiNiuYun
}

type Mysql struct {
	Host     string
	Port     string
	User     string
	Password string
	Database string
}

type Redis struct {
	Host     string
	Port     string
	Password string
	Database int
}

type Es struct {
	Address  string
	Username string
	Password string
}

type QiNiuYun struct {
	AccessKey string
	SecretKey string
	Bucket    string
	Url       string
}

var Config appConfig

func Init() {
	var err error
	viper.SetConfigFile("../appconfig/dev.yaml")
	err = viper.ReadInConfig()
	if err != nil {
		panic("获取配置文件失败")
	}
	err = viper.Unmarshal(&Config)
	if err != nil {
		panic("配置文件解析失败")
	}
	fmt.Println(&Config)
}
